package com.jiazhong.shuzu;

import java.util.Scanner;

public class Demo05 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("查找前n个数质数的个数，n：");
        int n=sc.nextInt();
        int a1[]={2};
        for (int i=3;i<=n;i++){
            for (int j=2;j<=i;j++) {
                if (i % j == 0)
                    break;
                else if(j==i-1) {
                    int []a2 = new int[a1.length + 1];
                    for (int k = 0; k < a1.length; k++) {
                        a2[k] = a1[k];
                    }
                    a2[a2.length - 1] = i;
                    a1 = a2;
                }
            }
        }
        for (int i=0;i<a1.length;i++){
            System.out.print(" "+a1[i]);
        }
    }
}
